<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page isELIgnored="false" %>
<html>
<head>
    <title>Title</title>
    <base href="<%=request.getContextPath()%>/">
    <link rel="stylesheet" href="static/layui/css/layui.css">
    <script src="static/jquery/jquery.js"></script>
    <script src="static/layui/layui.js"></script>
    <style>
        .layui-table-cell {
            height: auto;
        }
    </style>
</head>
<body>
<div style="width: 95%;margin: 5px auto">
    <form class="layui-form">
        <input type="hidden" name="userinfoId" value="${type.typeId}">
        <div class="layui-form-item">
            <label for="name" class="layui-form-label">类型名称</label>
            <div class="layui-input-block">
                <input type="text" value="${type.name}" name="name" id="name"
                       placeholder="类型名称"
                       lay-verify="required" lay-reqtext="请填写类型名称" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="num" class="layui-form-label">类型数量</label>
            <div class="layui-input-block">
                <input type="text" value="${type.num}" name="num" id="num"
                       placeholder="类型数量"
                       lay-verify="required" lay-reqtext="请填写类型数量" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"></label>
            <div class="layui-input-block">
                <button lay-submit class="layui-btn" lay-filter="update">提交</button>
            </div>
        </div>
    </form>
</div>
</body>
<script>
    var form;
    layui.use(function () {
        form = layui.form;
        form.on("submit(update)", function (data) {
            data.field.typeId =${type.typeId};
            $.ajax({
                url: "admin/order/type/update",
                data: data.field,
                method: "post",
                dataType: "json",
                success(res) {
                    console.log(res)
                    if (res.code === 200) {
                        layer.msg('操作成功！', {icon: 1}, function () {
                            /*获取当前窗口的标记值*/
                            const index = parent.layer.getFrameIndex(window.name);
                            /*关闭窗口*/
                            parent.layer.close(index);
                            /*刷新list中的表格*/
                            parent.table.reloadData('dataTable')
                        });
                    } else {
                        layer.alert(res.msg, {icon: 2});
                    }
                },
                error(e) {
                    layer.alert('服务器睡着了', {icon: 6})
                    console.log(e)
                }
            })
            return false;
        });

    })
</script>
</html>
